import { BasicColumn, FormSchema } from '/@/components/Table';
import { userRemarksColumn, userStatusColumn } from '@/settings/ShareTableColumns';
import { userRemarkFormItem, userStatusFormItem } from '@/settings/ShareFormItem';
import { rules } from '@/utils/common/validator';
import {
  apiGetCategoryCheckNameUniqueQuery,
  apiGetCategoryDropdowncategory,
} from '@/api/http/system/auxiliary/category/category.api';

export const useCategoryUpdateSchemaForm = (): FormSchema[] => {
  return [
    {
      field: 'pid',
      label: '所属类别',
      component: 'ApiTreeSelect',
      componentProps: { api: apiGetCategoryDropdowncategory, treeLine: { showLine: true } },
    },
    {
      field: 'name',
      label: '类别名称',
      component: 'Input',
      dynamicRules: ({ schema, model }) =>
        rules.uniqueFieldValidation(apiGetCategoryCheckNameUniqueQuery, 'id', schema, model, true),
    },
    {
      field: 'sort',
      label: '类别排序',
      component: 'InputNumber',
      required: true,
      componentProps: {
        min: 0,
        max: 10000,
      },
      defaultValue: 0,
    },
    userStatusFormItem(),
    userRemarkFormItem(),
    { field: 'id', label: '商品类别id', component: 'Input', show: false },
  ];
};

export const useCategoryListColumns = (): BasicColumn[] => {
  return [
    { title: '类别名称', dataIndex: 'name', align: 'left' },
    { title: '类别排序', dataIndex: 'sort' },
    userStatusColumn(),
    userRemarksColumn(),
  ];
};

export const useCategoryListSearchForm = (): FormSchema[] => {
  return [{ field: 'query', label: '', component: 'Input' }];
};

export const useCategoryAddSchemaForm = (): FormSchema[] => {
  return [
    { field: 'pid', label: '所属类别', component: 'Input' },
    { field: 'name', label: '类别名称', component: 'Input' },
    { field: 'sort', label: '类别排序', component: 'Input' },
    { field: 'remark', label: '备注信息', component: 'Input' },
    { field: 'status', label: '状态（1正常 0停用）', component: 'Input' },
  ];
};
